package com.example.demo.controller;

import com.example.demo.entity.CourseQuestion;
import com.example.demo.service.CourseQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseQuestions")
@CrossOrigin
public class CourseQuestionController {

    @Autowired
    private CourseQuestionService courseQuestionService;

    // 新增课程问题
    @PostMapping
    public int insertCourseQuestion(@RequestBody CourseQuestion courseQuestion) {
        return courseQuestionService.insertCourseQuestion(courseQuestion);
    }

    // 删除课程问题
    @DeleteMapping("/{id}")
    public int deleteCourseQuestionById(@PathVariable int id) {
        return courseQuestionService.deleteCourseQuestionById(id);
    }

    // 修改课程问题
    @PutMapping
    public int updateCourseQuestion(@RequestBody CourseQuestion courseQuestion) {
        return courseQuestionService.updateCourseQuestion(courseQuestion);
    }

    // 查询课程问题
    @GetMapping("/{id}")
    public CourseQuestion selectCourseQuestionById(@PathVariable int id) {
        return courseQuestionService.selectCourseQuestionById(id);
    }

    // 查询所有课程问题
    @GetMapping
    public List<CourseQuestion> selectAllCourseQuestions() {
        return courseQuestionService.selectAllCourseQuestions();
    }

    // 联合查询课程的所有问题
    @GetMapping("/course/{courseId}")
    public List<CourseQuestion> selectCourseQuestionsByCourseId(@PathVariable int courseId) {
        return courseQuestionService.selectCourseQuestionsByCourseId(courseId);
    }

    // 联合查询教师回答的所有问题
    @GetMapping("/teacher/{teacherId}")
    public List<CourseQuestion> selectCourseQuestionsByTeacherId(@PathVariable int teacherId) {
        return courseQuestionService.selectCourseQuestionsByTeacherId(teacherId);
    }
}
